home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import spamexperts
- import spamexperts.se_logging as spamexperts
- spamexperts.se_logging.setup('SpamExpertsUpdate')
- import os
- import sys
- import time
- import gettext
- import spamexperts.resources as spamexperts
- import spamexperts.software_update as spamexperts
-
- try:
- _
- except NameError:
- _ = gettext.gettext
- import __builtin__
- __builtin__.__dict__['_'] = _
-
-
- def simple_dialog(msg, can_cancel = False, yes_no = False):
- import wx
- if can_cancel:
- flags = wx.OK | wx.ICON_INFORMATION | wx.CANCEL
- elif yes_no:
- flags = wx.YES_NO | wx.ICON_QUESTION
- else:
- flags = wx.OK | wx.ICON_INFORMATION
- d = wx.MessageDialog(None, msg, 'SpamExperts', flags)
- result = d.ShowModal()
- if yes_no:
- if result == wx.ID_YES:
- result = wx.ID_OK
- elif result == wx.ID_NO:
- result = wx.ID_CANCEL
-
-
- d.Destroy()
- return result
-
-
- def complete_update():
- import wx
- initial_version = spamexperts.__version__
- progress_style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME
- if 'continue' in sys.argv:
- initial = _('Resuming update.')
- else:
- initial = _('Starting update.')
- dlg = wx.ProgressDialog(_('SpamExperts Update'), initial, maximum = 100, style = progress_style)
- software_update = spamexperts.software_update
- exe_dir = spamexperts.resources.application_directory()
- updater = software_update.CompleteUpdate()
- updater.update()
- dlg.Destroy()
- if initial_version.startswith('1.0.'):
- convert()
-
-
-
- def convert(files = True, logs = True, lsp = True, copyfile = True, shortcuts = True):
- LSP_INI_FULLPATH = LSP_INI_FULLPATH
- import se_config
- options = options
- import spamexperts.Options
- shell = shell
- shellcon = shellcon
- import win32com.shell
- data_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
- if files:
- for cache, opt in (('spam', 'spam_cache'), ('ham', 'ham_cache'), ('unsure', 'unsure_cache'), ('unknown', 'unknown_cache'), ('to_be_removed', 'to_be_removed_cache')):
- cache = os.path.join(data_dir, options[('Storage', 'user_data_dir')], cache)
- if os.path.isdir(cache):
- files = os.listdir(cache)
- for f in files:
- full_f = os.path.join(cache, f)
- out_f = os.path.join(data_dir, options[('Storage', 'user_data_dir')], options[('Storage', opt)], f)
- encrypt(full_f, out_f)
- os.remove(full_f)
-
- os.rmdir(cache)
- continue
-
-
- if logs:
- for i in xrange(4):
-
- try:
- os.remove(os.path.join(spamexperts.se_logging.log_dir, 'SpamExpertsServer%d.log' % (i,)))
- continue
- except OSError:
- continue
-
-
-
-
- if lsp:
- convert_lsp(LSP_INI_FULLPATH)
-
- if copyfile:
- convert_copyfile()
-
- if shortcuts:
- STARTMENU = shellcon.CSIDL_STARTMENU
- COMMON = shellcon.CSIDL_COMMON_STARTMENU
-
- try:
- start = shell.SHGetFolderPath(0, STARTMENU, 0, 0)
- except pywintypes.com_error:
- start = None
-
-
- try:
- common = shell.SHGetFolderPath(0, COMMON, 0, 0)
- except pywintypes.com_error:
- common = None
-
- for version in ('Programs', 'All Programs'):
- for user in (start, common):
- if user:
- continue
- _[1][user]
-
-
-
-
-
- def convert_copyfile():
- import _winreg
- import tempfile
- key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce')
- i = 0
- replacements = []
- while True:
-
- try:
- (name, unused, command) = _winreg.EnumValue(key, i)
- except WindowsError:
- break
-
- i += 1
- if name == 'update-se':
- _winreg.DeleteValue(key, name)
- continue
-
-
- try:
- (unused, new, old) = command.split('" "')
- except ValueError:
- continue
-
- old.rstrip('"')
- _winreg.DeleteValue(key, name)
- replacements.append((old, new))
- if not replacements:
- return None
-
- fn = os.path.join(tempfile.tempdir, 'spamexperts_update', 'in_use.txt')
- f = file(fn, 'w')
- f.write('"%s" continue relaunch\n' % (sys.executable,))
- for old, new in replacements:
- f.write('%s\n%s\n' % (new, old))
-
- f.close()
- cmd = os.path.join(os.path.dirname(sys.executable), 'copyfile.exe ' + fn)
- key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce')
- _winreg.SetValueEx(key, 'spamexperts update', 0, _winreg.REG_SZ, cmd)
-
-
- def add(ports):
- ports.extend([
- '995',
- '993'])
- return ports
-
-
- def convert_lsp(LSP_INI_FULLPATH):
- options = options
- import spamexperts.Options
- dest_port = options[('globals', 'proxy_redirection_port')]
- apps = { }
- ports = { }
- for line in file(LSP_INI_FULLPATH):
- (exe, port, to, description) = line.split(',')
- apps[exe] = description
-
- try:
- ports[exe].append(port)
- continue
- except KeyError:
- ports[exe] = [
- port]
- continue
-
-
-
- ports = dict((lambda [outmost-iterable]: for exe, port in [outmost-iterable]:
- (exe, add(port)))(ports.iteritems()))
- revised = file(LSP_INI_FULLPATH, 'w')
- for exe, port_list in ports.iteritems():
- for port in port_list:
- revised.write('%s,%s,%s,%s\n' % (exe, port, dest_port, apps[exe].rstrip()))
-
-
- revised.close()
-
-
- def encrypt(pn, out_pn):
- options = options
- import spamexperts.Options
- AES = AES
- import Crypto.Cipher
- if options[('globals', 'verbose')]:
- print 'Converting', pn, '...',
-
- key = '%.16i' % hash(out_pn.lower())[:16]
- crypt = AES.new(key)
- msg = file(pn).read()
- msg = crypt.encrypt(msg + '\x00' * (16 - len(msg) % 16))
-
- try:
- os.makedirs(os.path.dirname(out_pn))
- except OSError:
- pass
-
- file(out_pn, 'wb').write(msg)
- if options[('globals', 'verbose')]:
- print '... converted'
-
-
- if __name__ == '__main__':
- if 'convert_data' in sys.argv:
- print 'Converting data at', time.asctime(time.localtime())
- convert()
- else:
- import sys
- import urllib
- import _winreg
- (v_file, unused) = urllib.urlretrieve('http://update2.spamexperts.com/version.txt')
- content = file(v_file).read()
- if '<html>' in content.lower() and '404' in content:
- sys.exit()
-
- version = content.strip()
- urllib.urlcleanup()
- key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\SpamExperts')
- _winreg.SetValueEx(key, 'LatestBuild', 0, _winreg.REG_SZ, version)
-
-